<?php
if (!defined('ROOTPATH')) {
	die("permission deny");
//	require_once "../../config.php";
}

require_once ROOTPATH . "config.php";

/**
 * 数据库连接的封装器
 *
 * @author hutushen222
 * @version 1.0.0 2010-07-20
 */
class DBConnection {

	private $conn = null;
	private $dbSelect = null;
	private $result = null;

	/**
	 * 连接到数据库系统
	 */
	function connect() {
		$this->conn = mysql_connect(DBHOST, DBUSER, DBPASS)
		or die("Cannot connect to the database management system -- ".mysql_error());
		return $this->conn;
	}

	/**
	 * 一步连接数据库系统, 并选择相应数据库, 返回连接的数据库的连接
	 * AIO => all in one
	 */
	function connectAIO() {
		$this->connect();
		return $this->selectDB();
	}

	/**
	 * 选择要连接的数据库
	 */
	function selectDB() {
		$this->dbSelect = mysql_select_db(DBNAME)
		or die("Cannot connect to the database file -- ".mysql_error());
		return $this->dbSelect;
	}

	/**
	 * 执行指定地查询语句
	 */
	function query($sql) {
		$this->result = mysql_query($sql)
		or die("Cannot query current database -- ".mysql_error());
		return $this->result;
	}

	/**
	 *
	 */
	function affectedRows() {

		return mysql_affected_rows();
	}

	/**
	 * 关闭数据库的连接
	 */
	function close() {
		return mysql_close($this->conn);
	}
}
?>